import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { useI18n } from '/@/hooks/web/useI18n';
import * as evbApi from '/@/api/infra/eventBus';
const { t } = useI18n('');

const getStatusColor = (status) => {
  if (status === '1') return 'green';
  else if (status === '2') return 'red';
  else if (status === '3') return 'orange';
}

export const columns: BasicColumn[] = [
  {
    title: t('订阅编号'),
    dataIndex: 'subscribeId',
    width: 100,
  },
  {
    title: t('发布者'),
    dataIndex: 'publisherName',
    width: 130,
  },
  {
    title: t('主题'),
    dataIndex: 'topicName',
    width: 130,
  },
  {
    title: t('订阅者'),
    dataIndex: 'subscriberName',
    width: 130,
  },
  {
    title: t('状态'),
    dataIndex: 'statusName',
    customRender: ({ record }) => {
      return render.renderTag(record.statusName, getStatusColor(record.status))
    },
    width: 100,
  },
  {
    title: t('重试次数'),
    dataIndex: 'retryCount',
    width: 100,
  },
  {
    title: t('推送时间'),
    dataIndex: 'pushTime',
    width: 150,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: t('发布者'),
    field: 'publisherCode',
    component: 'ApiSelect',
    componentProps: {
      api: evbApi.listPublisher,
      showSearch: true,
      allowClear: true,
      labelField: 'name',
      valueField: 'code',
    },
  },
  {
    label: t('订阅者'),
    field: 'subscriberCode',
    component: 'ApiSelect',
    componentProps: {
      api: evbApi.listSubscriber,
      showSearch: true,
      allowClear: true,
      labelField: 'name',
      valueField: 'code',
    },
  },
  {
    label: t('状态'),
    field: 'status',
    component: "JDictSelectTag",
    componentProps: {
      dictType: "evb_notifyStatus",
      allowClear: true,
    },
  },
  {
    label: t('订阅编号'),
    field: 'subscribeId',
    component: 'Input',
  },
  {
    label: t('主题'),
    field: 'topicCode',
    component: 'Input',
  },
];


export const formDetailSchema: DescItem[] = [
  {
    label: t('TraceId'),
    field: 'traceId'
  },
  {
    label: t('订阅编号'),
    field: 'subscribeId'
  },
  {
    label: t('订阅主题'),
    field: 'topicName',
    render: (curVal, data) => {
      return `${curVal}（${data.topicCode}）`
    },
  },
  {
    label: t('发布者'),
    field: 'publisherName',
    render: (curVal, data) => {
      return `${curVal}（${data.publisherCode}）`
    },
  },
  {
    label: t('订阅者'),
    field: 'subscriberName',
    render: (curVal, data) => {
      return `${curVal}（${data.subscriberCode}）`
    },
  },
  {
    label: t('状态'),
    field: 'status',
    render: (curVal, data) => {
      return render.renderTag(data.statusName, getStatusColor(data.status))
    }
  },
  {
    label: t('重试次数'),
    field: 'retryCount'
  },
  {
    label: t('推送时间'),
    field: 'pushTime'
  },
  {
    label: t('推送结果'),
    field: 'pushResult'
  },
  {
    label: t('消息内容'),
    field: 'content'
  },
];
